package cn.qihua.service.impl;

import java.util.List;

import cn.qihua.dao.ILogOrderDAO;
import cn.qihua.dao.ILogProductDAO;
import cn.qihua.model.LogOrder;
import cn.qihua.model.LogProduct;
import cn.qihua.service.ILogService;

public class LogService implements ILogService {

	private ILogProductDAO logProductDAO;
	private ILogOrderDAO logOrderDAO;

	/* (non-Javadoc)
	 * @see cn.qihua.service.impl.ILogService#findProductById(java.lang.Integer)
	 */
	@Override
	public LogProduct findLogProductById(Integer id) {
		return logProductDAO.findById(id);
	}

	/* (non-Javadoc)
	 * @see cn.qihua.service.impl.ILogService#findProductByProperty(java.lang.String, java.lang.Object)
	 */
	@Override
	@SuppressWarnings("unchecked")
	public List<LogProduct> findLogProductByProperty(String propertyName,
			Object value) {
		return logProductDAO.findByProperty(propertyName, value);
	}

	/* (non-Javadoc)
	 * @see cn.qihua.service.impl.ILogService#findProductByUserId(java.lang.Integer)
	 */

//	public List<LogProduct> findLogProductByUserId(Integer userId) {
//		return logProductDAO.findByUserId(userId);
//	}
	@Override
	@SuppressWarnings("unchecked")
	public List<LogProduct> findLogProductByProductId(Integer productId) {
		return logProductDAO.findByProductId(productId);
	}
	/* (non-Javadoc)
	 * @see cn.qihua.service.impl.ILogService#add(cn.qihua.model.LogProduct)
	 */
	@Override
	public boolean add(LogProduct transientInstance) {
		logProductDAO.save(transientInstance);
		return true;
	}

	/* (non-Javadoc)
	 * @see cn.qihua.service.impl.ILogService#delProduct(java.lang.Integer)
	 */
	@Override
	public boolean delLogProduct(Integer id) {
		LogProduct log = logProductDAO.findById(id);
		if (log != null) {
			logProductDAO.delete(log);
			return true;
		} else {
			return false;
		}
	}

	/* (non-Javadoc)
	 * @see cn.qihua.service.impl.ILogService#edit(cn.qihua.model.LogProduct)
	 */
	@Override
	public boolean edit(LogProduct transientInstance) {
		return logProductDAO.update(transientInstance);
	}

	// Order
	/* (non-Javadoc)
	 * @see cn.qihua.service.impl.ILogService#findOrderById(java.lang.Integer)
	 */
	@Override
	public LogOrder findLogOrderById(Integer id) {
		return logOrderDAO.findById(id);
	}

	/* (non-Javadoc)
	 * @see cn.qihua.service.impl.ILogService#findOrderByProperty(java.lang.String, java.lang.Object)
	 */
	@Override
	@SuppressWarnings("unchecked")
	public List<LogOrder> findLogOrderByProperty(String propertyName, Object value) {
		return logOrderDAO.findByProperty(propertyName, value);
	}


//	public List<LogOrder> findLogOrderByUserId(Integer userId) {
//		return logOrderDAO.findByUserId(userId);
//	}
	
	
	@Override
	@SuppressWarnings("unchecked")
	public List<LogOrder> findLogOrderByOrderId(Integer orderId) {
		return logOrderDAO.findByOrderId(orderId);
	}
	
	/* (non-Javadoc)
	 * @see cn.qihua.service.impl.ILogService#add(cn.qihua.model.LogOrder)
	 */
	@Override
	public boolean add(LogOrder transientInstance) {
		logOrderDAO.save(transientInstance);
		return true;
	}

	/* (non-Javadoc)
	 * @see cn.qihua.service.impl.ILogService#delOrder(java.lang.Integer)
	 */
	@Override
	public boolean delLogOrder(Integer id) {
		LogOrder log = logOrderDAO.findById(id);
		if (log != null) {
			logOrderDAO.delete(log);
			return true;
		} else {
			return false;
		}
	}

	/* (non-Javadoc)
	 * @see cn.qihua.service.impl.ILogService#edit(cn.qihua.model.LogOrder)
	 */
	@Override
	public boolean edit(LogOrder transientInstance) {
		return logOrderDAO.update(transientInstance);
	}

	/* (non-Javadoc)
	 * @see cn.qihua.service.impl.ILogService#setLogProductDAO(cn.qihua.dao.ILogProductDAO)
	 */
	@Override
	public void setLogProductDAO(ILogProductDAO logProductDAO) {
		this.logProductDAO = logProductDAO;
	}

	/* (non-Javadoc)
	 * @see cn.qihua.service.impl.ILogService#setLogOrderDAO(cn.qihua.dao.ILogOrderDAO)
	 */
	@Override
	public void setLogOrderDAO(ILogOrderDAO logOrderDAO) {
		this.logOrderDAO = logOrderDAO;
	}

}
